import { defHttp } from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";
import { identity } from 'lodash-es';
import { log } from 'console';

const { createConfirm } = useMessage();

enum Api {
  list = '/utensil/labUtensil/list',
  // save='/utensil/labUtensil/add',
  // edit='/utensil/labUtensil/edit',
  deleteOne = '/utensil/labUtensil/delete',
  deleteBatch = '/utensil/labUtensil/deleteBatch',
  importExcel = '/utensil/labUtensil/importExcel',
  exportXls = '/utensil/labUtensil/exportXls',
  updateSure = '/utensil/labUtensil/updateSure',
  queryNote = '/utensil/labUtensilNote/queryNote',
  listCheck = '/utensil/labUtensil/listCheck',
  checking = '/utensil/labUtensil/checking',
  queryAll = '/utensil/labUtensilCheck/queryAllCheck',
  checkId = '/utensil/labUtensilCheck/checkId',
  save = '/utensil/labUtensilCheck/add',
  edit = '/utensil/labUtensilCheck/edit',
}

/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) => defHttp.get({ url: Api.list, params });
//待检定器具
export const listCheck = (params) => defHttp.get({ url: Api.listCheck, params });
//检定中器具
export const checking = (params) => defHttp.get({ url: Api.checking, params });
/**
 * 删除单个
 * @param params
 * @param handleSuccess
 */
export const deleteOne = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
}

/**
 * 批量删除
 * @param params
 * @param handleSuccess
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    }
  });
}

/**
 * 保存或者更新
 * @param params
 * @param isUpdate
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params }, { isTransformResponse: false });
}

//填写确认单
export const updateSure = (params, isUpdate) => {
  let url = isUpdate ? Api.updateSure : Api.save;
  return defHttp.post({ url: url, params }, { isTransformResponse: false });
}

/**
 * 根据器具id查确认记录
 * @param isUpdate 
 * @returns 
 */
export const queryNote = (params) => defHttp.get({ url: '/utensil/labUtensilNote/queryNote?' + 'id=' + params });

//查询所有待检定
export const queryAll = (ids) => defHttp.get({ url: Api.queryAll, params: ids });
//根据申请单id查询清单内容回显
export const checkId = (id) => defHttp.get({ url: Api.checkId, params: { id } });